package routers

import (
	"mime"
	"myerp/controllers"
	"os"

	"myerp/models"
	. "myerp/src/tool"

	"github.com/astaxie/beego"
)

func init() {

	initialize()
	router()
	beego.AddFuncMap("stringsToJson", StringtoJson)
}
func initialize() {

	mime.AddExtensionType(".css", "text/css")

	args := os.Args
	for _, v := range args {
		if v == "InitDB" {
			// 创建表 插入数据等等，只在执行./CStore InitDB 时候执行一次
			models.InitDB()
			os.Exit(0)
		}
	}
	// 链接数据库
	models.Connect()
}
func router() {
	//全部考虑改成自动路由
	beego.SetStaticPath("/assets", "static/assets")
	beego.Router("/", &controllers.IndexController{}, "*:Index")
	beego.AutoRouter(&controllers.MainController{})
	beego.AutoRouter(&controllers.UserController{})
	beego.AutoRouter(&controllers.RoleController{})
	beego.AutoRouter(&controllers.ResController{})
	beego.AutoRouter(&controllers.SaleController{})      //销售
	beego.AutoRouter(&controllers.DepotController{})     //仓库
	beego.AutoRouter(&controllers.GoodsController{})     //商品
	beego.AutoRouter(&controllers.SortsController{})     //分类
	beego.AutoRouter(&controllers.OutgoingController{})  //出库
	beego.AutoRouter(&controllers.StorageController{})   //入库
	beego.AutoRouter(&controllers.PurchaseController{})  //采购
	beego.AutoRouter(&controllers.ClientsController{})   //客户
	beego.AutoRouter(&controllers.PersonnelController{}) //人事管理
	beego.AutoRouter(&controllers.FinanceController{})   //财务
	beego.AutoRouter(&controllers.AreaController{})      //地区
	// beego.Router("/", &controllers.MainController{}, "*:Index")
	// beego.Router("/myerp/index", &controllers.MainController{}, "*:Index")
	// beego.Router("/myerp/login", &controllers.MainController{}, "*:Login")
	// beego.Router("/myerp/logout", &controllers.MainController{}, "*:Logout")
	// beego.Router("/myerp/changepwd", &controllers.MainController{}, "*:ChangePwd")
	// beego.Router("/myerp/mainFrame", &controllers.MainController{}, "*:MainFrame")

	// beego.Router("/myerp/background/top", &controllers.MainController{}, "*:Top")
	// beego.Router("/myerp/background/center", &controllers.MainController{}, "*:Center")
	// beego.Router("/myerp/background/left", &controllers.MainController{}, "*:Left")
	// beego.Router("/myerp/background/tab", &controllers.MainController{}, "*:Tab")

	// beego.Router("/myerp/user/list", &controllers.UserController{}, "*:List")
	// beego.Router("/myerp/user/edit", &controllers.UserController{}, "*:Edit")
	// beego.Router("/myerp/user/delete", &controllers.UserController{}, "*:Delete")
	// beego.Router("/myerp/user/add", &controllers.UserController{}, "*:Add")
	// beego.Router("/myerp/user/role", &controllers.UserController{}, "*:AllocationRole")
	// beego.Router("/myerp/user/allocation", &controllers.UserController{}, "*:Allocation")

	// beego.Router("/myerp/role/list", &controllers.RoleController{}, "*:List")
	// beego.Router("/myerp/role/add", &controllers.RoleController{}, "*:Add")
	// beego.Router("/myerp/role/delete", &controllers.RoleController{}, "*:Delete")
	// beego.Router("/myerp/role/edit", &controllers.RoleController{}, "*:Edit")
	// beego.Router("/myerp/role/resource", &controllers.RoleController{}, "*:AllocationRes")

	// beego.Router("/myerp/resource/list", &controllers.ResController{}, "*:List")
	// beego.Router("/myerp/resource/add", &controllers.ResController{}, "*:Add")
	// beego.Router("/myerp/resource/delete", &controllers.ResController{}, "*:Delete")
	// beego.Router("/myerp/resource/edit", &controllers.ResController{}, "*:Edit")
	// beego.Router("/myerp/resource/saveRoleRescours", &controllers.ResController{}, "*:SaveRoleRescours")
	// beego.Router("/myerp/resource/show", &controllers.ResController{}, "*:Show")

	//其他的使用自动路由来完成
}
